package com.baidu.acg.industry.bigdata.client;

import com.baidu.acg.industry.bigdata.config.ApplicationConfiguration;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MinioClientFactory {
    @Autowired
    private ApplicationConfiguration modelConfiguration;
    private volatile MinioClient minioClient = null;

    public MinioClient createMinioClient() {
        if (minioClient == null) {
            synchronized (this) {
                if (minioClient == null) {
                    minioClient = MinioClient.builder()
                            .endpoint(modelConfiguration.getMinioEndpoint())
                            .credentials(modelConfiguration.getMinioAK(), modelConfiguration.getMinioSK())
                            .build();
                }
            }
        }
        return minioClient;
    }
}
